<?php
require_once PATH_SITE.'cn/royan/php/proxys/SocketProxy.proxy.php';
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
require_once PATH_SITE.'org/puremvc/php/patterns/proxy/Proxy.php';
/**
 * Description of UserDisconnectProxy
 *
 * @author yanr
 */
class UserDisconnectProxy extends Proxy
{
    const NAME = "UserDisconnectProxy";
    protected $socketProxy;
    //put your code here
    public function __construct() {
        parent::__construct( UserDisconnectProxy::NAME );
        $this->socketProxy = $this->facade->retrieveProxy( SocketProxy::NAME );
    }
    
    public function removeUser( $connect )
    {
        $socket = $this->socketProxy->getData();
        $clients = & $socket->__get( "clientInfos" );
        
        $users = array();
        
        FOR( $i = 0; $i < count( $clients ); $i++ )
            IF( isset( $clients[$i] ) && $clients[$i]->__get("socket") != $connect )
                array_push( $users, $clients[$i] );
        
        $connects = & $socket->__get( "connects" );
        FOR( $i = 0; $i < count( $connects ); $i++ )
        {
            IF( isset( $connects[$i] ) && $connects[$i] == $connect )
            {
                Logger::trace( "Disconnect...".$connects[$i] );
                socket_close( $connects[$i] );
                $connects[$i] = NULL;
            }
        }
            
        $socket->__set( "clientInfos", $users );
    }
}
?>